package com.alt.www.sort;

/**
 * Created by 27340 on 2017/9/16.
 */
public class MergeSort {
    public static void sort(Comparable[] a, int lo, int mid, int hi){
        //将a[lo..mid]和 a[mid+1..hi]归并
        int i = lo, j = mid+1;
        Comparable[] aux = new Comparable[hi-1];
        for (int k = lo; k <=hi ; k++) {
            aux[k] = a[k];
        }
        for (int k = lo; k <= hi ; k++) {
            if(i > mid)                           a[k] = aux[j++];
            else if(j > hi)                       a[k] = aux[i++];
            else if(Example.less(aux[j], aux[i])) a[k] = aux[j++];
            else                                  a[k] = aux[i++];
        }

    }
}
